<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>canvas</title>
  <style>
    canvas {
      border: 1px solid #000;
    }
  </style>
</head>

<body>
  <canvas width="500" height="400" id="my-canvas">
    当前浏览器版本不支持，请升级浏览器
  </canvas>

  <script>
    // 1. 获取到canvas画布
    var canvas = document.getElementById("my-canvas");
    // 得到画布的上下文
    // - 2d上下文
    var ctx = canvas.getContext("2d");
    // 设置颜色
    ctx.fillStyle = "green";
    // 绘制矩形 fillRect(x, y, 宽, 高)
    ctx.fillRect(0, 0, 200, 200);
    console.log(ctx);
  </script>
</body>

</html>